
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>10.2 生成输出头文件 · 《CMake Cookbook》中文版</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="陈晓伟 chenxiaowei">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="10.3-chinese.html" />
    
    
    <link rel="prev" href="10.1-chinese.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../preface/preface-chinese.html">
            
                <a href="../preface/preface-chinese.html">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../chapter0/0.0-chinese.html">
            
                <a href="../chapter0/0.0-chinese.html">
            
                    
                    第0章 配置环境
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../chapter0/0.1-chinese.html">
            
                <a href="../chapter0/0.1-chinese.html">
            
                    
                    0.1 获取代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../chapter0/0.2-chinese.html">
            
                <a href="../chapter0/0.2-chinese.html">
            
                    
                    0.2 Docker镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../chapter0/0.3-chinese.html">
            
                <a href="../chapter0/0.3-chinese.html">
            
                    
                    0.3 安装必要的软件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../chapter0/0.4-chinese.html">
            
                <a href="../chapter0/0.4-chinese.html">
            
                    
                    0.4 测试环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../chapter0/0.5-chinese.html">
            
                <a href="../chapter0/0.5-chinese.html">
            
                    
                    0.5 上报问题并提出改进建议
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../chapter1/1.0-chinese.html">
            
                <a href="../chapter1/1.0-chinese.html">
            
                    
                    第1章 从可执行文件到库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../chapter1/1.1-chinese.html">
            
                <a href="../chapter1/1.1-chinese.html">
            
                    
                    1.1 将单个源文件编译为可执行文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../chapter1/1.2-chinese.html">
            
                <a href="../chapter1/1.2-chinese.html">
            
                    
                    1.2 切换生成器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../chapter1/1.3-chinese.html">
            
                <a href="../chapter1/1.3-chinese.html">
            
                    
                    1.3 构建和链接静态库和动态库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../chapter1/1.4-chinese.html">
            
                <a href="../chapter1/1.4-chinese.html">
            
                    
                    1.4 用条件句控制编译
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../chapter1/1.5-chinese.html">
            
                <a href="../chapter1/1.5-chinese.html">
            
                    
                    1.5 向用户显示选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../chapter1/1.6-chinese.html">
            
                <a href="../chapter1/1.6-chinese.html">
            
                    
                    1.6 指定编译器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../chapter1/1.7-chinese.html">
            
                <a href="../chapter1/1.7-chinese.html">
            
                    
                    1.7 切换构建类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../chapter1/1.8-chinese.html">
            
                <a href="../chapter1/1.8-chinese.html">
            
                    
                    1.8 设置编译器选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="../chapter1/1.9-chinese.html">
            
                <a href="../chapter1/1.9-chinese.html">
            
                    
                    1.9 为语言设定标准
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="../chapter1/1.10-chinese.html">
            
                <a href="../chapter1/1.10-chinese.html">
            
                    
                    1.10 使用控制流
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../chapter2/2.0-chinese.html">
            
                <a href="../chapter2/2.0-chinese.html">
            
                    
                    第2章 检测环境
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../chapter2/2.1-chinese.html">
            
                <a href="../chapter2/2.1-chinese.html">
            
                    
                    2.1 检测操作系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../chapter2/2.2-chinese.html">
            
                <a href="../chapter2/2.2-chinese.html">
            
                    
                    2.2 处理与平台相关的源代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../chapter2/2.3-chinese.html">
            
                <a href="../chapter2/2.3-chinese.html">
            
                    
                    2.3 处理与编译器相关的源代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../chapter2/2.4-chinese.html">
            
                <a href="../chapter2/2.4-chinese.html">
            
                    
                    2.4 检测处理器体系结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../chapter2/2.5-chinese.html">
            
                <a href="../chapter2/2.5-chinese.html">
            
                    
                    2.5 检测处理器指令集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../chapter2/2.6-chinese.html">
            
                <a href="../chapter2/2.6-chinese.html">
            
                    
                    2.6 为Eigen库使能向量化
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../chapter3/3.0-chinese.html">
            
                <a href="../chapter3/3.0-chinese.html">
            
                    
                    第3章 检测外部库和程序
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../chapter3/3.1-chinese.html">
            
                <a href="../chapter3/3.1-chinese.html">
            
                    
                    3.1 检测Python解释器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../chapter3/3.2-chinese.html">
            
                <a href="../chapter3/3.2-chinese.html">
            
                    
                    3.2 检测Python库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../chapter3/3.3-chinese.html">
            
                <a href="../chapter3/3.3-chinese.html">
            
                    
                    3.3 检测Python模块和包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../chapter3/3.4-chinese.html">
            
                <a href="../chapter3/3.4-chinese.html">
            
                    
                    3.4 检测BLAS和LAPACK数学库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../chapter3/3.5-chinese.html">
            
                <a href="../chapter3/3.5-chinese.html">
            
                    
                    3.5 检测OpenMP的并行环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../chapter3/3.6-chinese.html">
            
                <a href="../chapter3/3.6-chinese.html">
            
                    
                    3.6 检测MPI的并行环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../chapter3/3.7-chinese.html">
            
                <a href="../chapter3/3.7-chinese.html">
            
                    
                    3.7 检测Eigen库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../chapter3/3.8-chinese.html">
            
                <a href="../chapter3/3.8-chinese.html">
            
                    
                    3.8 检测Boost库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../chapter3/3.9-chinese.html">
            
                <a href="../chapter3/3.9-chinese.html">
            
                    
                    3.9 检测外部库:Ⅰ. 使用pkg-config
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../chapter3/3.10-chinese.html">
            
                <a href="../chapter3/3.10-chinese.html">
            
                    
                    3.10 检测外部库:Ⅱ. 自定义find模块
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../chapter4/4.0-chinese.html">
            
                <a href="../chapter4/4.0-chinese.html">
            
                    
                    第4章 创建和运行测试
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../chapter4/4.1-chinese.html">
            
                <a href="../chapter4/4.1-chinese.html">
            
                    
                    4.1 创建一个简单的单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../chapter4/4.2-chinese.html">
            
                <a href="../chapter4/4.2-chinese.html">
            
                    
                    4.2 使用Catch2库进行单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../chapter4/4.3-chinese.html">
            
                <a href="../chapter4/4.3-chinese.html">
            
                    
                    4.3 使用Google Test库进行单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../chapter4/4.4-chinese.html">
            
                <a href="../chapter4/4.4-chinese.html">
            
                    
                    4.4 使用Boost Test进行单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../chapter4/4.5-chinese.html">
            
                <a href="../chapter4/4.5-chinese.html">
            
                    
                    4.5 使用动态分析来检测内存缺陷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../chapter4/4.6-chinese.html">
            
                <a href="../chapter4/4.6-chinese.html">
            
                    
                    4.6 预期测试失败
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="../chapter4/4.7-chinese.html">
            
                <a href="../chapter4/4.7-chinese.html">
            
                    
                    4.7 使用超时测试运行时间过长的测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.8" data-path="../chapter4/4.8-chinese.html">
            
                <a href="../chapter4/4.8-chinese.html">
            
                    
                    4.8 并行测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.9" data-path="../chapter4/4.9-chinese.html">
            
                <a href="../chapter4/4.9-chinese.html">
            
                    
                    4.9 运行测试子集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.10" data-path="../chapter4/4.10-chinese.html">
            
                <a href="../chapter4/4.10-chinese.html">
            
                    
                    4.10 使用测试固件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../chapter5/5.0-chinese.html">
            
                <a href="../chapter5/5.0-chinese.html">
            
                    
                    第5章 配置时和构建时的操作
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../chapter5/5.1-chinese.html">
            
                <a href="../chapter5/5.1-chinese.html">
            
                    
                    5.1 使用平台无关的文件操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../chapter5/5.2-chinese.html">
            
                <a href="../chapter5/5.2-chinese.html">
            
                    
                    5.2 配置时运行自定义命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../chapter5/5.3-chinese.html">
            
                <a href="../chapter5/5.3-chinese.html">
            
                    
                    5.3 构建时运行自定义命令:Ⅰ. 使用add_custom_command
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../chapter5/5.4-chinese.html">
            
                <a href="../chapter5/5.4-chinese.html">
            
                    
                    5.4 构建时运行自定义命令:Ⅱ. 使用add_custom_target
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../chapter5/5.5-chinese.html">
            
                <a href="../chapter5/5.5-chinese.html">
            
                    
                    5.5 构建时为特定目标运行自定义命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="../chapter5/5.6-chinese.html">
            
                <a href="../chapter5/5.6-chinese.html">
            
                    
                    5.6 探究编译和链接命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="../chapter5/5.7-chinese.html">
            
                <a href="../chapter5/5.7-chinese.html">
            
                    
                    5.7 探究编译器标志命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="../chapter5/5.8-chinese.html">
            
                <a href="../chapter5/5.8-chinese.html">
            
                    
                    5.8 探究可执行命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.9" data-path="../chapter5/5.9-chinese.html">
            
                <a href="../chapter5/5.9-chinese.html">
            
                    
                    5.9 使用生成器表达式微调配置和编译
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../chapter6/6.0-chinese.html">
            
                <a href="../chapter6/6.0-chinese.html">
            
                    
                    第6章 生成源码
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../chapter6/6.1-chinese.html">
            
                <a href="../chapter6/6.1-chinese.html">
            
                    
                    6.1 配置时生成源码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../chapter6/6.2-chinese.html">
            
                <a href="../chapter6/6.2-chinese.html">
            
                    
                    6.2 使用Python在配置时生成源码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../chapter6/6.3-chinese.html">
            
                <a href="../chapter6/6.3-chinese.html">
            
                    
                    6.3 构建时使用Python生成源码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" data-path="../chapter6/6.4-chinese.html">
            
                <a href="../chapter6/6.4-chinese.html">
            
                    
                    6.4 记录项目版本信息以便报告
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.5" data-path="../chapter6/6.5-chinese.html">
            
                <a href="../chapter6/6.5-chinese.html">
            
                    
                    6.5 从文件中记录项目版本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.6" data-path="../chapter6/6.6-chinese.html">
            
                <a href="../chapter6/6.6-chinese.html">
            
                    
                    6.6 配置时记录Git Hash值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.7" data-path="../chapter6/6.7-chinese.html">
            
                <a href="../chapter6/6.7-chinese.html">
            
                    
                    6.7 构建时记录Git Hash值
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../chapter7/7.0-chinese.html">
            
                <a href="../chapter7/7.0-chinese.html">
            
                    
                    第7章 构建项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../chapter7/7.1-chinese.html">
            
                <a href="../chapter7/7.1-chinese.html">
            
                    
                    7.1 使用函数和宏重用代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../chapter7/7.2-chinese.html">
            
                <a href="../chapter7/7.2-chinese.html">
            
                    
                    7.2 将CMake源代码分成模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../chapter7/7.3-chinese.html">
            
                <a href="../chapter7/7.3-chinese.html">
            
                    
                    7.3 编写函数来测试和设置编译器标志
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../chapter7/7.4-chinese.html">
            
                <a href="../chapter7/7.4-chinese.html">
            
                    
                    7.4 用指定参数定义函数或宏
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../chapter7/7.5-chinese.html">
            
                <a href="../chapter7/7.5-chinese.html">
            
                    
                    7.5 重新定义函数和宏
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="../chapter7/7.6-chinese.html">
            
                <a href="../chapter7/7.6-chinese.html">
            
                    
                    7.6 使用废弃函数、宏和变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.7" data-path="../chapter7/7.7-chinese.html">
            
                <a href="../chapter7/7.7-chinese.html">
            
                    
                    7.7 add_subdirectory的限定范围
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.8" data-path="../chapter7/7.8-chinese.html">
            
                <a href="../chapter7/7.8-chinese.html">
            
                    
                    7.8 使用target_sources避免全局变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.9" data-path="../chapter7/7.9-chinese.html">
            
                <a href="../chapter7/7.9-chinese.html">
            
                    
                    7.9 组织Fortran项目
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../chapter8/8.0-chinese.html">
            
                <a href="../chapter8/8.0-chinese.html">
            
                    
                    第8章 超级构建模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../chapter8/8.1-chinese.html">
            
                <a href="../chapter8/8.1-chinese.html">
            
                    
                    8.1 使用超级构建模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../chapter8/8.2-chinese.html">
            
                <a href="../chapter8/8.2-chinese.html">
            
                    
                    8.2 使用超级构建管理依赖项:Ⅰ.Boost库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../chapter8/8.3-chinese.html">
            
                <a href="../chapter8/8.3-chinese.html">
            
                    
                    8.3 使用超级构建管理依赖项:Ⅱ.FFTW库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../chapter8/8.4-chinese.html">
            
                <a href="../chapter8/8.4-chinese.html">
            
                    
                    8.4 使用超级构建管理依赖项:Ⅲ.Google Test框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../chapter8/8.5-chinese.html">
            
                <a href="../chapter8/8.5-chinese.html">
            
                    
                    8.5 使用超级构建支持项目
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../chapter9/9.0-chinese.html">
            
                <a href="../chapter9/9.0-chinese.html">
            
                    
                    第9章 语言混合项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../chapter9/9.1-chinese.html">
            
                <a href="../chapter9/9.1-chinese.html">
            
                    
                    9.1 使用C/C++库构建Fortran项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../chapter9/9.2-chinese.html">
            
                <a href="../chapter9/9.2-chinese.html">
            
                    
                    9.2 使用Fortran库构建C/C++项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="../chapter9/9.3-chinese.html">
            
                <a href="../chapter9/9.3-chinese.html">
            
                    
                    9.3 使用Cython构建C++和Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.4" data-path="../chapter9/9.4-chinese.html">
            
                <a href="../chapter9/9.4-chinese.html">
            
                    
                    9.4 使用Boost.Python构建C++和Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.5" data-path="../chapter9/9.5-chinese.html">
            
                <a href="../chapter9/9.5-chinese.html">
            
                    
                    9.5 使用pybind11构建C++和Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.6" data-path="../chapter9/9.6-chinese.html">
            
                <a href="../chapter9/9.6-chinese.html">
            
                    
                    9.6 使用Python CFFI混合C，C++，Fortran和Python
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="10.0-chinese.html">
            
                <a href="10.0-chinese.html">
            
                    
                    第10章 编写安装程序
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="10.1-chinese.html">
            
                <a href="10.1-chinese.html">
            
                    
                    10.1 安装项目
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.13.2" data-path="10.2-chinese.html">
            
                <a href="10.2-chinese.html">
            
                    
                    10.2 生成输出头文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="10.3-chinese.html">
            
                <a href="10.3-chinese.html">
            
                    
                    10.3 输出目标
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.4" data-path="10.4-chinese.html">
            
                <a href="10.4-chinese.html">
            
                    
                    10.4 安装超级构建
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../chapter11/11.0-chinese.html">
            
                <a href="../chapter11/11.0-chinese.html">
            
                    
                    第11章 打包项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1" data-path="../chapter11/11.1-chinese.html">
            
                <a href="../chapter11/11.1-chinese.html">
            
                    
                    11.1 生成源代码和二进制包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2" data-path="../chapter11/11.2-chinese.html">
            
                <a href="../chapter11/11.2-chinese.html">
            
                    
                    11.2 通过PyPI发布使用CMake/pybind11构建的C++/Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.3" data-path="../chapter11/11.3-chinese.html">
            
                <a href="../chapter11/11.3-chinese.html">
            
                    
                    11.3 通过PyPI发布使用CMake/CFFI构建C/Fortran/Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.4" data-path="../chapter11/11.4-chinese.html">
            
                <a href="../chapter11/11.4-chinese.html">
            
                    
                    11.4 以Conda包的形式发布一个简单的项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.5" data-path="../chapter11/11.5-chinese.html">
            
                <a href="../chapter11/11.5-chinese.html">
            
                    
                    11.5 将Conda包作为依赖项发布给项目
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../chapter12/12.0-chinese.html">
            
                <a href="../chapter12/12.0-chinese.html">
            
                    
                    第12章 构建文档
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../chapter12/12.1-chinese.html">
            
                <a href="../chapter12/12.1-chinese.html">
            
                    
                    12.1 使用Doxygen构建文档
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2" data-path="../chapter12/12.2-chinese.html">
            
                <a href="../chapter12/12.2-chinese.html">
            
                    
                    12.2 使用Sphinx构建文档
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3" data-path="../chapter12/12.3-chinese.html">
            
                <a href="../chapter12/12.3-chinese.html">
            
                    
                    12.3 结合Doxygen和Sphinx
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../chapter13/13.0-chinese.html">
            
                <a href="../chapter13/13.0-chinese.html">
            
                    
                    第13章 选择生成器和交叉编译
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.16.1" data-path="../chapter13/13.1-chinese.html">
            
                <a href="../chapter13/13.1-chinese.html">
            
                    
                    13.1 使用CMake构建Visual Studio 2017项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.2" data-path="../chapter13/13.2-chinese.html">
            
                <a href="../chapter13/13.2-chinese.html">
            
                    
                    13.2 交叉编译hello world示例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.3" data-path="../chapter13/13.3-chinese.html">
            
                <a href="../chapter13/13.3-chinese.html">
            
                    
                    13.3 使用OpenMP并行化交叉编译Windows二进制文件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="../chapter14/14.0-chinese.html">
            
                <a href="../chapter14/14.0-chinese.html">
            
                    
                    第14章 测试面板
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.17.1" data-path="../chapter14/14.1-chinese.html">
            
                <a href="../chapter14/14.1-chinese.html">
            
                    
                    14.1 将测试部署到CDash
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.2" data-path="../chapter14/14.2-chinese.html">
            
                <a href="../chapter14/14.2-chinese.html">
            
                    
                    14.2 CDash显示测试覆盖率
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.3" data-path="../chapter14/14.3-chinese.html">
            
                <a href="../chapter14/14.3-chinese.html">
            
                    
                    14.3 使用AddressSanifier向CDash报告内存缺陷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.4" data-path="../chapter14/14.4-chinese.html">
            
                <a href="../chapter14/14.4-chinese.html">
            
                    
                    14.4 使用ThreadSaniiser向CDash报告数据争用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="../chapter15/15.0-chinese.html">
            
                <a href="../chapter15/15.0-chinese.html">
            
                    
                    第15章 使用CMake构建已有项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.18.1" data-path="../chapter15/15.1-chinese.html">
            
                <a href="../chapter15/15.1-chinese.html">
            
                    
                    15.1 如何开始迁移项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.2" data-path="../chapter15/15.2-chinese.html">
            
                <a href="../chapter15/15.2-chinese.html">
            
                    
                    15.2 生成文件并编写平台检查
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.3" data-path="../chapter15/15.3-chinese.html">
            
                <a href="../chapter15/15.3-chinese.html">
            
                    
                    15.3 检测所需的链接和依赖关系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.4" data-path="../chapter15/15.4-chinese.html">
            
                <a href="../chapter15/15.4-chinese.html">
            
                    
                    15.4 复制编译标志
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.5" data-path="../chapter15/15.5-chinese.html">
            
                <a href="../chapter15/15.5-chinese.html">
            
                    
                    15.5 移植测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.6" data-path="../chapter15/15.6-chinese.html">
            
                <a href="../chapter15/15.6-chinese.html">
            
                    
                    15.6 移植安装目标
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.7" data-path="../chapter15/15.7-chinese.html">
            
                <a href="../chapter15/15.7-chinese.html">
            
                    
                    15.7 进一步迁移的措施
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.8" data-path="../chapter15/15.8-chinese.html">
            
                <a href="../chapter15/15.8-chinese.html">
            
                    
                    15.8 项目转换为CMake的常见问题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="../chapter16/16.0-chinese.html">
            
                <a href="../chapter16/16.0-chinese.html">
            
                    
                    第16章 可能感兴趣的书
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.19.1" data-path="../chapter16/16.1-chinese.html">
            
                <a href="../chapter16/16.1-chinese.html">
            
                    
                    16.1 留下评论——让其他读者知道你的想法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="http://www.bczl.xyz/" target="blank" class="gitbook-link">
            编程之路
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >10.2 生成输出头文件</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="102-&#x751F;&#x6210;&#x8F93;&#x51FA;&#x5934;&#x6587;&#x4EF6;">10.2 &#x751F;&#x6210;&#x8F93;&#x51FA;&#x5934;&#x6587;&#x4EF6;</h1>
<p><strong>NOTE</strong>:<em>&#x6B64;&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#x53EF;&#x4EE5;&#x5728; <a href="https://github.com/dev-cafe/cmake-cookbook/tree/v1.0/chapter-10/recipe-02" target="_blank">https://github.com/dev-cafe/cmake-cookbook/tree/v1.0/chapter-10/recipe-02</a> &#x4E2D;&#x627E;&#x5230;&#xFF0C;&#x5176;&#x4E2D;&#x6709;&#x4E00;&#x4E2A;C++&#x793A;&#x4F8B;&#x3002;&#x8BE5;&#x793A;&#x4F8B;&#x5728;CMake 3.6&#x7248;(&#x6216;&#x66F4;&#x9AD8;&#x7248;&#x672C;)&#x4E2D;&#x662F;&#x6709;&#x6548;&#x7684;&#xFF0C;&#x5E76;&#x4E14;&#x5DF2;&#x7ECF;&#x5728;GNU/Linux&#x3001;macOS&#x548C;Windows&#x4E0A;&#x8FDB;&#x884C;&#x8FC7;&#x6D4B;&#x8BD5;&#x3002;</em></p>
<p>&#x8BBE;&#x60F3;&#x4E00;&#x4E0B;&#xFF0C;&#x5F53;&#x6211;&#x4EEC;&#x7684;&#x5C0F;&#x578B;&#x5E93;&#x975E;&#x5E38;&#x53D7;&#x6B22;&#x8FCE;&#x65F6;&#xFF0C;&#x8BB8;&#x591A;&#x4EBA;&#x90FD;&#x5728;&#x4F7F;&#x7528;&#x5B83;&#x3002;&#x7136;&#x800C;&#xFF0C;&#x4E00;&#x4E9B;&#x5BA2;&#x6237;&#x5E0C;&#x671B;&#x5728;&#x5B89;&#x88C5;&#x65F6;&#x4F7F;&#x7528;&#x9759;&#x6001;&#x5E93;&#xFF0C;&#x800C;&#x53E6;&#x4E00;&#x4E9B;&#x5BA2;&#x6237;&#x4E5F;&#x6CE8;&#x610F;&#x5230;&#x6240;&#x6709;&#x7B26;&#x53F7;&#x5728;&#x52A8;&#x6001;&#x5E93;&#x4E2D;&#x90FD;&#x662F;&#x53EF;&#x89C1;&#x7684;&#x3002;&#x6700;&#x4F73;&#x65B9;&#x5F0F;&#x662F;&#x89C4;&#x5B9A;&#x52A8;&#x6001;&#x5E93;&#x53EA;&#x516C;&#x5F00;&#x6700;&#x5C0F;&#x7684;&#x7B26;&#x53F7;&#xFF0C;&#x4ECE;&#x800C;&#x9650;&#x5236;&#x4EE3;&#x7801;&#x4E2D;&#x5B9A;&#x4E49;&#x7684;&#x5BF9;&#x8C61;&#x548C;&#x51FD;&#x6570;&#x5BF9;&#x5916;&#x7684;&#x53EF;&#x89C1;&#x6027;&#x3002;&#x6211;&#x4EEC;&#x5E0C;&#x671B;&#x5728;&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x52A8;&#x6001;&#x5E93;&#x5B9A;&#x4E49;&#x7684;&#x6240;&#x6709;&#x7B26;&#x53F7;&#x90FD;&#x5BF9;&#x5916;&#x9690;&#x85CF;&#x3002;&#x8FD9;&#x5C06;&#x4F7F;&#x5F97;&#x9879;&#x76EE;&#x7684;&#x8D21;&#x732E;&#x8005;&#xFF0C;&#x80FD;&#x591F;&#x6E05;&#x695A;&#x5730;&#x5212;&#x5206;&#x5E93;&#x548C;&#x5916;&#x90E8;&#x4EE3;&#x7801;&#x4E4B;&#x95F4;&#x7684;&#x63A5;&#x53E3;&#xFF0C;&#x56E0;&#x4E3A;&#x4ED6;&#x4EEC;&#x5FC5;&#x987B;&#x663E;&#x5F0F;&#x5730;&#x6807;&#x8BB0;&#x6240;&#x6709;&#x8981;&#x5728;&#x9879;&#x76EE;&#x5916;&#x90E8;&#x4F7F;&#x7528;&#x7684;&#x7B26;&#x53F7;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x5B8C;&#x6210;&#x4EE5;&#x4E0B;&#x5DE5;&#x4F5C;&#xFF1A;</p>
<ul>
<li>&#x4F7F;&#x7528;&#x540C;&#x4E00;&#x7EC4;&#x6E90;&#x6587;&#x4EF6;&#x6784;&#x5EFA;&#x52A8;&#x6001;&#x5E93;&#x548C;&#x9759;&#x6001;&#x5E93;</li>
<li>&#x786E;&#x4FDD;&#x6B63;&#x786E;&#x5206;&#x9694;&#x52A8;&#x6001;&#x5E93;&#x4E2D;&#x7B26;&#x53F7;&#x7684;&#x53EF;&#x89C1;&#x6027;</li>
</ul>
<p>&#x7B2C;1&#x7AE0;&#x7B2C;3&#x8282;&#x4E2D;&#xFF0C;&#x5DF2;&#x7ECF;&#x5C55;&#x793A;&#x4E86;CMake&#x63D0;&#x4F9B;&#x4E86;&#x4E0E;&#x5E73;&#x53F0;&#x65E0;&#x5173;&#x7684;&#x65B9;&#x5F0F;&#x5B9E;&#x73B0;&#x7684;&#x529F;&#x80FD;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x6CA1;&#x6709;&#x5904;&#x7406;&#x7B26;&#x53F7;&#x53EF;&#x89C1;&#x6027;&#x7684;&#x95EE;&#x9898;&#x3002;&#x6211;&#x4EEC;&#x5C06;&#x7528;&#x5F53;&#x524D;&#x7684;&#x914D;&#x65B9;&#x91CD;&#x65B0;&#x8BA8;&#x8BBA;&#x8FD9;&#x4E24;&#x70B9;&#x3002;</p>
<h2 id="&#x51C6;&#x5907;&#x5DE5;&#x4F5C;">&#x51C6;&#x5907;&#x5DE5;&#x4F5C;</h2>
<p>&#x6211;&#x4EEC;&#x4ECD;&#x5C06;&#x4F7F;&#x7528;&#x4E0E;&#x524D;&#x4E00;&#x4E2A;&#x793A;&#x4F8B;&#x4E2D;&#x57FA;&#x672C;&#x76F8;&#x540C;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x4F46;&#x662F;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x4FEE;&#x6539;<code>src/CMakeLists.txt</code>&#x548C;<code>Message.hpp</code>&#x5934;&#x6587;&#x4EF6;&#x3002;&#x540E;&#x8005;&#x5C06;&#x5305;&#x62EC;&#x65B0;&#x7684;&#x3001;&#x81EA;&#x52A8;&#x751F;&#x6210;&#x7684;&#x5934;&#x6587;&#x4EF6;<code>messageExport.h</code>:</p>
<pre><code class="lang-c++"><span class="hljs-meta">#<span class="hljs-meta-keyword">pragma</span> once</span>

<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span></span>

<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-string">&quot;messageExport.h&quot;</span></span>

<span class="hljs-keyword">class</span> message_EXPORT Message
{
<span class="hljs-keyword">public</span>:
  Message(<span class="hljs-keyword">const</span> <span class="hljs-built_in">std</span>::<span class="hljs-built_in">string</span> &amp;m) : message_(m) {}

  <span class="hljs-keyword">friend</span> <span class="hljs-built_in">std</span>::ostream &amp;<span class="hljs-keyword">operator</span>&lt;&lt;(<span class="hljs-built_in">std</span>::ostream &amp;os, Message &amp;obj)
  {
    <span class="hljs-keyword">return</span> obj.printObject(os);
  }

<span class="hljs-keyword">private</span>:
  <span class="hljs-built_in">std</span>::<span class="hljs-built_in">string</span> message_;
  <span class="hljs-built_in">std</span>::<span class="hljs-function">ostream &amp;<span class="hljs-title">printObject</span><span class="hljs-params">(<span class="hljs-built_in">std</span>::ostream &amp;os)</span></span>;
};

<span class="hljs-built_in">std</span>::<span class="hljs-function"><span class="hljs-built_in">string</span> <span class="hljs-title">getUUID</span><span class="hljs-params">()</span></span>;
</code></pre>
<p><code>Message</code>&#x7C7B;&#x7684;&#x58F0;&#x660E;&#x4E2D;&#x5F15;&#x5165;&#x4E86;<code>message_EXPORT</code>&#x9884;&#x5904;&#x7406;&#x5668;&#x6307;&#x4EE4;&#xFF0C;&#x8FD9;&#x4E2A;&#x6307;&#x4EE4;&#x5C06;&#x8BA9;&#x7F16;&#x8BD1;&#x5668;&#x751F;&#x6210;&#x5BF9;&#x5E93;&#x7684;&#x7528;&#x6237;&#x53EF;&#x89C1;&#x7684;&#x7B26;&#x53F7;&#x3002;</p>
<h2 id="&#x5177;&#x4F53;&#x5B9E;&#x65BD;">&#x5177;&#x4F53;&#x5B9E;&#x65BD;</h2>
<p>&#x9664;&#x4E86;&#x9879;&#x76EE;&#x7684;&#x540D;&#x79F0;&#x5916;&#xFF0C;&#x4E3B;<code>CMakeLists.txt</code>&#x6587;&#x4EF6;&#x6CA1;&#x6709;&#x6539;&#x53D8;&#x3002;&#x9996;&#x5148;&#xFF0C;&#x770B;&#x770B;<code>src</code>&#x5B50;&#x76EE;&#x5F55;&#x4E2D;&#x7684;<code>CMakeLists.txt</code>&#x6587;&#x4EF6;&#xFF0C;&#x6240;&#x6709;&#x5DE5;&#x4F5C;&#x5B9E;&#x9645;&#x4E0A;&#x90FD;&#x5728;&#x8FD9;&#x91CC;&#x8FDB;&#x884C;&#x3002;&#x6211;&#x4EEC;&#x5C06;&#x91CD;&#x70B9;&#x5C55;&#x793A;&#x5BF9;&#x4E4B;&#x524D;&#x793A;&#x4F8B;&#x7684;&#x4FEE;&#x6539;&#x4E4B;&#x5904;:</p>
<ol>
<li><p>&#x4E3A;&#x6D88;&#x606F;&#x4F20;&#x9012;&#x5E93;&#x58F0;&#x660E;<code>SHARED</code>&#x5E93;&#x76EE;&#x6807;&#x53CA;&#x5176;&#x6E90;&#x3002;&#x6CE8;&#x610F;&#xFF0C;&#x7F16;&#x8BD1;&#x5B9A;&#x4E49;&#x548C;&#x94FE;&#x63A5;&#x5E93;&#x6CA1;&#x6709;&#x6539;&#x53D8;:    </p>
<pre><code class="lang-cmake"><span class="hljs-keyword">add_library</span>(<span class="hljs-keyword">message</span>-shared SHARED <span class="hljs-string">&quot;&quot;</span>)

target_sources(<span class="hljs-keyword">message</span>-shared
  PRIVATE
      <span class="hljs-variable">${CMAKE_CURRENT_LIST_DIR}</span>/<span class="hljs-keyword">Message</span>.cpp
  )

target_compile_definitions(<span class="hljs-keyword">message</span>-shared
    PUBLIC
      $&lt;$&lt;BOOL:<span class="hljs-variable">${UUID_FOUND}</span>&gt;:HAVE_UUID&gt;
  )

<span class="hljs-keyword">target_link_libraries</span>(<span class="hljs-keyword">message</span>-shared
  PUBLIC
      $&lt;$&lt;BOOL:<span class="hljs-variable">${UUID_FOUND}</span>&gt;:PkgConfig::UUID&gt;
  )
</code></pre>
</li>
<li><p>&#x8BBE;&#x7F6E;&#x76EE;&#x6807;&#x5C5E;&#x6027;&#x3002;&#x5C06;<code>${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}/messageExport.h</code>&#x5934;&#x6587;&#x4EF6;&#x6DFB;&#x52A0;&#x5230;&#x516C;&#x5171;&#x5934;&#x5217;&#x8868;&#x4E2D;&#xFF0C;&#x4F5C;&#x4E3A;<code>PUBLIC_HEADER</code>&#x76EE;&#x6807;&#x5C5E;&#x6027;&#x7684;&#x53C2;&#x6570;&#x3002;<code>CXX_VISIBILITY_PRESET</code>&#x7F6E;&#x548C;<code>VISIBILITY_INLINES_HIDDEN</code>&#x5C5E;&#x6027;&#x5C06;&#x5728;&#x4E0B;&#x4E00;&#x8282;&#x4E2D;&#x8BA8;&#x8BBA;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">set_target_properties</span>(<span class="hljs-keyword">message</span>-shared
  PROPERTIES
    POSITION_INDEPENDENT_CODE <span class="hljs-number">1</span>
    CXX_VISIBILITY_PRESET hidden
    VISIBILITY_INLINES_HIDDEN <span class="hljs-number">1</span>
    SOVERSION <span class="hljs-variable">${PROJECT_VERSION_MAJOR}</span>
    OUTPUT_NAME <span class="hljs-string">&quot;message&quot;</span>
    DEBUG_POSTFIX <span class="hljs-string">&quot;_d&quot;</span>
    PUBLIC_HEADER <span class="hljs-string">&quot;Message.hpp;${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}/messageExport.h&quot;</span>
    MACOSX_RPATH <span class="hljs-keyword">ON</span>
  )
</code></pre>
</li>
<li><p>&#x5305;&#x542B;<code>GenerateExportHeader.cmake</code>&#x6A21;&#x5757;&#x5E76;&#x8C03;&#x7528;<code>generate_export_header</code>&#x51FD;&#x6570;&#xFF0C;&#x8FD9;&#x5C06;&#x5728;&#x6784;&#x5EFA;&#x76EE;&#x5F55;&#x7684;&#x5B50;&#x76EE;&#x5F55;&#x4E2D;&#x751F;&#x6210;<code>messageExport.h</code>&#x5934;&#x6587;&#x4EF6;&#x3002;&#x6211;&#x4EEC;&#x5C06;&#x7A0D;&#x540E;&#x4F1A;&#x8BE6;&#x7EC6;&#x8BA8;&#x8BBA;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x548C;&#x751F;&#x6210;&#x7684;&#x5934;&#x6587;&#x4EF6;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">include</span>(GenerateExportHeader)
generate_export_header(<span class="hljs-keyword">message</span>-shared
  BASE_NAME <span class="hljs-string">&quot;message&quot;</span>
  EXPORT_MACRO_NAME <span class="hljs-string">&quot;message_EXPORT&quot;</span>
  EXPORT_FILE_NAME <span class="hljs-string">&quot;${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}/messageExport.h&quot;</span>
  DEPRECATED_MACRO_NAME <span class="hljs-string">&quot;message_DEPRECATED&quot;</span>
  NO_EXPORT_MACRO_NAME <span class="hljs-string">&quot;message_NO_EXPORT&quot;</span>
  STATIC_DEFINE <span class="hljs-string">&quot;message_STATIC_DEFINE&quot;</span>
  NO_DEPRECATED_MACRO_NAME <span class="hljs-string">&quot;message_NO_DEPRECATED&quot;</span>
  DEFINE_NO_DEPRECATED
  )
</code></pre>
</li>
<li><p>&#x5F53;&#x8981;&#x66F4;&#x6539;&#x7B26;&#x53F7;&#x7684;&#x53EF;&#x89C1;&#x6027;(&#x4ECE;&#x5176;&#x9ED8;&#x8BA4;&#x503C;-&#x9690;&#x85CF;&#x503C;)&#x65F6;&#xFF0C;&#x90FD;&#x5E94;&#x8BE5;&#x5305;&#x542B;&#x5BFC;&#x51FA;&#x5934;&#x6587;&#x4EF6;&#x3002;&#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x5728;<code>Message.hpp</code>&#x5934;&#x6587;&#x4EF6;&#x4F8B;&#x8FD9;&#x6837;&#x505A;&#x4E86;&#xFF0C;&#x56E0;&#x4E3A;&#x60F3;&#x5728;&#x5E93;&#x4E2D;&#x516C;&#x5F00;&#x4E00;&#x4E9B;&#x7B26;&#x53F7;&#x3002;&#x73B0;&#x5728;&#x5C06;<code>${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}</code>&#x76EE;&#x5F55;&#x4F5C;&#x4E3A;<code>message-shared</code>&#x76EE;&#x6807;&#x7684;<code>PUBLIC</code>&#x5305;&#x542B;&#x76EE;&#x5F55;&#x5217;&#x51FA;&#xFF1A;</p>
<pre><code class="lang-cmake">target_include_directories(<span class="hljs-keyword">message</span>-shared
  PUBLIC
      <span class="hljs-variable">${CMAKE_BINARY_DIR}</span>/<span class="hljs-variable">${INSTALL_INCLUDEDIR}</span>
  )
</code></pre>
</li>
</ol>
<p>&#x73B0;&#x5728;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x6CE8;&#x610F;&#x529B;&#x8F6C;&#x5411;&#x9759;&#x6001;&#x5E93;&#x7684;&#x751F;&#x6210;&#xFF1A;</p>
<ol>
<li><p>&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x5E93;&#x76EE;&#x6807;&#x6765;&#x751F;&#x6210;&#x9759;&#x6001;&#x5E93;&#x3002;&#x5C06;&#x7F16;&#x8BD1;&#x4E0E;&#x9759;&#x6001;&#x5E93;&#x76F8;&#x540C;&#x7684;&#x6E90;&#x6587;&#x4EF6;&#xFF0C;&#x4EE5;&#x83B7;&#x5F97;&#x6B64;&#x52A8;&#x6001;&#x5E93;&#x76EE;&#x6807;&#xFF1A;</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">add_library</span>(<span class="hljs-keyword">message</span>-static STATIC <span class="hljs-string">&quot;&quot;</span>)
target_sources(<span class="hljs-keyword">message</span>-static
  PRIVATE
      <span class="hljs-variable">${CMAKE_CURRENT_LIST_DIR}</span>/<span class="hljs-keyword">Message</span>.cpp
  )
</code></pre>
</li>
<li><p>&#x8BBE;&#x7F6E;&#x7F16;&#x8BD1;&#x5668;&#x5B9A;&#x4E49;&#xFF0C;&#x5305;&#x542B;&#x76EE;&#x5F55;&#x548C;&#x94FE;&#x63A5;&#x5E93;&#xFF0C;&#x5C31;&#x50CF;&#x6211;&#x4EEC;&#x4E3A;&#x52A8;&#x6001;&#x5E93;&#x76EE;&#x6807;&#x6240;&#x505A;&#x7684;&#x4E00;&#x6837;&#x3002;&#x4F46;&#x8BF7;&#x6CE8;&#x610F;&#xFF0C;&#x6211;&#x4EEC;&#x6DFB;&#x52A0;&#x4E86;<code>message_STATIC_DEFINE</code>&#x7F16;&#x8BD1;&#x65F6;&#x5B8F;&#x5B9A;&#x4E49;&#xFF0C;&#x4E3A;&#x4E86;&#x786E;&#x4FDD;&#x6211;&#x4EEC;&#x7684;&#x7B26;&#x53F7;&#x53EF;&#x4EE5;&#x9002;&#x5F53;&#x5730;&#x66B4;&#x9732;:</p>
<pre><code class="lang-cmake">target_compile_definitions(<span class="hljs-keyword">message</span>-static
  PUBLIC
      message_STATIC_DEFINE
      $&lt;$&lt;BOOL:<span class="hljs-variable">${UUID_FOUND}</span>&gt;:HAVE_UUID&gt;
  )

target_include_directories(<span class="hljs-keyword">message</span>-static
      PUBLIC
      <span class="hljs-variable">${CMAKE_BINARY_DIR}</span>/<span class="hljs-variable">${INSTALL_INCLUDEDIR}</span>
  )

<span class="hljs-keyword">target_link_libraries</span>(<span class="hljs-keyword">message</span>-static
  PUBLIC
      $&lt;$&lt;BOOL:<span class="hljs-variable">${UUID_FOUND}</span>&gt;:PkgConfig::UUID&gt;
  )
</code></pre>
</li>
<li><p>&#x8FD8;&#x8BBE;&#x7F6E;&#x4E86;<code>message-static</code>&#x76EE;&#x6807;&#x7684;&#x5C5E;&#x6027;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">set_target_properties</span>(<span class="hljs-keyword">message</span>-static
  PROPERTIES
    POSITION_INDEPENDENT_CODE <span class="hljs-number">1</span>
    ARCHIVE_OUTPUT_NAME <span class="hljs-string">&quot;message&quot;</span>
    DEBUG_POSTFIX <span class="hljs-string">&quot;_sd&quot;</span>
    RELEASE_POSTFIX <span class="hljs-string">&quot;_s&quot;</span>
    PUBLIC_HEADER <span class="hljs-string">&quot;Message.hpp;${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}/messageExport.h&quot;</span>
  )
</code></pre>
</li>
<li><p>&#x9664;&#x4E86;&#x94FE;&#x63A5;&#x5230;&#x6D88;&#x606F;&#x52A8;&#x6001;&#x5E93;&#x76EE;&#x6807;&#x7684;<code>hello-world_wDSO</code>&#x53EF;&#x6267;&#x884C;&#x76EE;&#x6807;&#x4E4B;&#x5916;&#xFF0C;&#x8FD8;&#x5B9A;&#x4E49;&#x4E86;&#x53E6;&#x4E00;&#x4E2A;&#x53EF;&#x6267;&#x884C;&#x76EE;&#x6807;<code>hello-world_wAR</code>&#xFF0C;&#x8FD9;&#x4E2A;&#x94FE;&#x63A5;&#x6307;&#x5411;&#x9759;&#x6001;&#x5E93;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">add_executable</span>(hello-world_wAR hello-world.cpp)

<span class="hljs-keyword">target_link_libraries</span>(hello-world_wAR
    PUBLIC
        <span class="hljs-keyword">message</span>-static
    )
</code></pre>
</li>
<li><p>&#x5B89;&#x88C5;&#x6307;&#x4EE4;&#x73B0;&#x5728;&#x591A;&#x4E86;<code>message-static</code>&#x548C;<code>hello-world_wAR</code>&#x76EE;&#x6807;&#xFF0C;&#x5176;&#x4ED6;&#x6CA1;&#x6709;&#x6539;&#x53D8;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">install</span>(
  TARGETS
    <span class="hljs-keyword">message</span>-shared
    <span class="hljs-keyword">message</span>-static
    hello-world_wDSO
    hello-world_wAR
  ARCHIVE
    DESTINATION <span class="hljs-variable">${INSTALL_LIBDIR}</span>
    COMPONENT lib
  RUNTIME
    DESTINATION <span class="hljs-variable">${INSTALL_BINDIR}</span>
    COMPONENT bin
  LIBRARY
    DESTINATION <span class="hljs-variable">${INSTALL_LIBDIR}</span>
    COMPONENT lib
  PUBLIC_HEADER
    DESTINATION <span class="hljs-variable">${INSTALL_INCLUDEDIR}</span>/<span class="hljs-keyword">message</span>
    COMPONENT dev
  )
</code></pre>
</li>
</ol>
<h2 id="&#x5DE5;&#x4F5C;&#x539F;&#x7406;">&#x5DE5;&#x4F5C;&#x539F;&#x7406;</h2>
<p>&#x6B64;&#x793A;&#x4F8B;&#x6F14;&#x793A;&#x4E86;&#xFF0C;&#x5982;&#x4F55;&#x8BBE;&#x7F6E;&#x52A8;&#x6001;&#x5E93;&#x7684;&#x7B26;&#x53F7;&#x53EF;&#x89C1;&#x6027;&#x3002;&#x6700;&#x597D;&#x7684;&#x65B9;&#x5F0F;&#x662F;&#x5728;&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#x9690;&#x85CF;&#x6240;&#x6709;&#x7B26;&#x53F7;&#xFF0C;&#x663E;&#x5F0F;&#x5730;&#x53EA;&#x516C;&#x5F00;&#x90A3;&#x4E9B;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x7684;&#x7B26;&#x53F7;&#x3002;&#x8FD9;&#x9700;&#x8981;&#x5206;&#x4E3A;&#x4E24;&#x6B65;&#x5B9E;&#x73B0;&#x3002;&#x9996;&#x5148;&#xFF0C;&#x9700;&#x8981;&#x6307;&#x793A;&#x7F16;&#x8BD1;&#x5668;&#x9690;&#x85CF;&#x7B26;&#x53F7;&#x3002;&#x5F53;&#x7136;&#xFF0C;&#x4E0D;&#x540C;&#x7684;&#x7F16;&#x8BD1;&#x5668;&#x5C06;&#x6709;&#x4E0D;&#x540C;&#x7684;&#x53EF;&#x7528;&#x9009;&#x9879;&#xFF0C;&#x5E76;&#x4E14;&#x76F4;&#x63A5;&#x5728;<code>CMakeLists.txt</code>&#x4E2D;&#x8BBE;&#x7F6E;&#x8FD9;&#x4E9B;&#x9009;&#x9879;&#x5E76;&#x4E0D;&#x662F;&#x662F;&#x8DE8;&#x5E73;&#x53F0;&#x7684;&#x3002;CMake&#x901A;&#x8FC7;&#x5728;&#x52A8;&#x6001;&#x5E93;&#x76EE;&#x6807;&#x4E0A;&#x8BBE;&#x7F6E;&#x4E24;&#x4E2A;&#x5C5E;&#x6027;&#xFF0C;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x79CD;&#x5065;&#x58EE;&#x7684;&#x8DE8;&#x5E73;&#x53F0;&#x65B9;&#x6CD5;&#x6765;&#x8BBE;&#x7F6E;&#x7B26;&#x53F7;&#x7684;&#x53EF;&#x89C1;&#x6027;&#xFF1A;</p>
<ul>
<li><code>CXX_VISIBILITY_PRESET hidden</code>&#xFF1A;&#x8FD9;&#x5C06;&#x9690;&#x85CF;&#x6240;&#x6709;&#x7B26;&#x53F7;&#xFF0C;&#x9664;&#x975E;&#x663E;&#x5F0F;&#x5730;&#x6807;&#x8BB0;&#x4E86;&#x5176;&#x4ED6;&#x7B26;&#x53F7;&#x3002;&#x5F53;&#x4F7F;&#x7528;GNU&#x7F16;&#x8BD1;&#x5668;&#x65F6;&#xFF0C;&#x8FD9;&#x5C06;&#x4E3A;&#x76EE;&#x6807;&#x6DFB;&#x52A0;<code>-fvisibility=hidden</code>&#x6807;&#x5FD7;&#x3002;</li>
<li><code>VISIBILITY_INLINES_HIDDEN 1</code>&#xFF1A;&#x8FD9;&#x5C06;&#x9690;&#x85CF;&#x5185;&#x8054;&#x51FD;&#x6570;&#x7684;&#x7B26;&#x53F7;&#x3002;&#x5982;&#x679C;&#x4F7F;&#x7528;GNU&#x7F16;&#x8BD1;&#x5668;&#xFF0C;&#x8FD9;&#x5BF9;&#x5E94;&#x4E8E;<code>-fvisibility-inlines-hidden</code></li>
</ul>
<p>Windows&#x4E0A;&#xFF0C;&#x8FD9;&#x90FD;&#x662F;&#x9ED8;&#x8BA4;&#x884C;&#x4E3A;&#x3002;&#x5B9E;&#x9645;&#x4E0A;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x5728;&#x524D;&#x9762;&#x7684;&#x793A;&#x4F8B;&#x4E2D;&#x901A;&#x8FC7;&#x8BBE;&#x7F6E;<code>WINDOWS_EXPORT_ALL_SYMBOLS</code>&#x5C5E;&#x6027;&#x4E3A;<code>ON</code>&#x6765;&#x8986;&#x76D6;&#x5B83;&#x3002;</p>
<p>&#x5982;&#x4F55;&#x6807;&#x8BB0;&#x53EF;&#x89C1;&#x7684;&#x7B26;&#x53F7;&#xFF1F;&#x8FD9;&#x7531;&#x9884;&#x5904;&#x7406;&#x5668;&#x51B3;&#x5B9A;&#xFF0C;&#x56E0;&#x6B64;&#x9700;&#x8981;&#x63D0;&#x4F9B;&#x76F8;&#x5E94;&#x7684;&#x9884;&#x5904;&#x7406;&#x5B8F;&#xFF0C;&#x8FD9;&#x4E9B;&#x5B8F;&#x53EF;&#x4EE5;&#x6269;&#x5C55;&#x5230;&#x6240;&#x9009;&#x5E73;&#x53F0;&#x4E0A;&#xFF0C;&#x4EE5;&#x4FBF;&#x7F16;&#x8BD1;&#x5668;&#x80FD;&#x591F;&#x7406;&#x89E3;&#x53EF;&#x89C1;&#x6027;&#x5C5E;&#x6027;&#x3002;CMake&#x4E2D;&#x6709;&#x73B0;&#x6210;&#x7684;<code>GenerateExportHeader.cmake</code>&#x6A21;&#x5757;&#x3002;&#x8FD9;&#x4E2A;&#x6A21;&#x5757;&#x5B9A;&#x4E49;&#x4E86;<code>generate_export_header</code>&#x51FD;&#x6570;&#xFF0C;&#x6211;&#x4EEC;&#x8C03;&#x7528;&#x5B83;&#x7684;&#x8FC7;&#x7A0B;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">include</span>(GenerateExportHeader)
generate_export_header(<span class="hljs-keyword">message</span>-shared
  BASE_NAME <span class="hljs-string">&quot;message&quot;</span>
  EXPORT_MACRO_NAME <span class="hljs-string">&quot;message_EXPORT&quot;</span>
  EXPORT_FILE_NAME <span class="hljs-string">&quot;${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}/messageExport.h&quot;</span>
  DEPRECATED_MACRO_NAME <span class="hljs-string">&quot;message_DEPRECATED&quot;</span>
  NO_EXPORT_MACRO_NAME <span class="hljs-string">&quot;message_NO_EXPORT&quot;</span>
  STATIC_DEFINE <span class="hljs-string">&quot;message_STATIC_DEFINE&quot;</span>
  NO_DEPRECATED_MACRO_NAME <span class="hljs-string">&quot;message_NO_DEPRECATED&quot;</span>
  DEFINE_NO_DEPRECATED
  )
</code></pre>
<p>&#x8BE5;&#x51FD;&#x6570;&#x751F;&#x6210;<code>messageExport.h</code>&#x5934;&#x6587;&#x4EF6;&#xFF0C;&#x5176;&#x4E2D;&#x5305;&#x542B;&#x9884;&#x5904;&#x7406;&#x5668;&#x6240;&#x9700;&#x7684;&#x5B8F;&#x3002;&#x6839;&#x636E;<code>EXPORT_FILE_NAME</code>&#x9009;&#x9879;&#x7684;&#x8BF7;&#x6C42;&#xFF0C;&#x5728;&#x76EE;&#x5F55;<code>${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}</code>&#x4E2D;&#x751F;&#x6210;&#x8BE5;&#x6587;&#x4EF6;&#x3002;&#x5982;&#x679C;&#x8BE5;&#x9009;&#x9879;&#x4E3A;&#x7A7A;&#xFF0C;&#x5219;&#x5934;&#x6587;&#x4EF6;&#x5C06;&#x5728;&#x5F53;&#x524D;&#x4E8C;&#x8FDB;&#x5236;&#x76EE;&#x5F55;&#x4E2D;&#x751F;&#x6210;&#x3002;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x73B0;&#x6709;&#x7684;&#x76EE;&#x6807;(&#x793A;&#x4F8B;&#x4E2D;&#x662F;<code>message-
shared</code>)&#xFF0C;&#x51FD;&#x6570;&#x7684;&#x57FA;&#x672C;&#x8C03;&#x7528;&#x53EA;&#x9700;&#x8981;&#x4F20;&#x9012;&#x73B0;&#x6709;&#x76EE;&#x6807;&#x7684;&#x540D;&#x79F0;&#x5373;&#x53EF;&#x3002;&#x53EF;&#x9009;&#x53C2;&#x6570;&#xFF0C;&#x7528;&#x4E8E;&#x7EC6;&#x7C92;&#x5EA6;&#x7684;&#x63A7;&#x5236;&#x6240;&#x6709;&#x751F;&#x6210;&#x5B8F;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x4F20;&#x9012;&#xFF1A;</p>
<ul>
<li>BASE_NAME&#xFF1A;&#x8BBE;&#x7F6E;&#x751F;&#x6210;&#x7684;&#x5934;&#x6587;&#x4EF6;&#x548C;&#x5B8F;&#x7684;&#x540D;&#x79F0;&#x3002;</li>
<li>EXPORT_MACRO_NAME&#xFF1A;&#x8BBE;&#x7F6E;&#x5BFC;&#x51FA;&#x5B8F;&#x7684;&#x540D;&#x79F0;&#x3002;</li>
<li>EXPORT_FILE_NAME&#xFF1A;&#x8BBE;&#x7F6E;&#x5BFC;&#x51FA;&#x5934;&#x6587;&#x4EF6;&#x7684;&#x540D;&#x79F0;&#x3002;</li>
<li>DEPRECATED_MACRO_NAME&#xFF1A;&#x8BBE;&#x7F6E;&#x5F03;&#x7528;&#x5B8F;&#x7684;&#x540D;&#x79F0;&#x3002;&#x8FD9;&#x662F;&#x7528;&#x6765;&#x6807;&#x8BB0;&#x5C06;&#x8981;&#x5E9F;&#x5F03;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x5982;&#x679C;&#x5BA2;&#x6237;&#x4F7F;&#x7528;&#x8BE5;&#x5B8F;&#x5B9A;&#x4E49;&#xFF0C;&#x7F16;&#x8BD1;&#x5668;&#x5C06;&#x53D1;&#x51FA;&#x4E00;&#x4E2A;&#x5C06;&#x8981;&#x5E9F;&#x5F03;&#x7684;&#x8B66;&#x544A;&#x3002;</li>
<li>NO_EXPORT_MACRO_NAME&#xFF1A;&#x8BBE;&#x7F6E;&#x4E0D;&#x5BFC;&#x51FA;&#x5B8F;&#x7684;&#x540D;&#x5B57;&#x3002;</li>
<li>STATIC_DEFINE&#xFF1A;&#x7528;&#x4E8E;&#x5B9A;&#x4E49;&#x5B8F;&#x7684;&#x540D;&#x79F0;&#xFF0C;&#x4EE5;&#x4FBF;&#x4F7F;&#x7528;&#x76F8;&#x540C;&#x6E90;&#x7F16;&#x8BD1;&#x9759;&#x6001;&#x5E93;&#x65F6;&#x4F7F;&#x7528;&#x3002;</li>
<li>NO_DEPRECATED_MACRO_NAME&#xFF1A;&#x8BBE;&#x7F6E;&#x5B8F;&#x7684;&#x540D;&#x79F0;&#xFF0C;&#x5728;&#x7F16;&#x8BD1;&#x65F6;&#x5C06;&#x201C;&#x5C06;&#x8981;&#x5E9F;&#x5F03;&#x201D;&#x7684;&#x4EE3;&#x7801;&#x6392;&#x9664;&#x5728;&#x5916;&#x3002;</li>
<li>DEFINE_NO_DEPRECATED&#xFF1A;&#x6307;&#x793A;CMake&#x751F;&#x6210;&#x9884;&#x5904;&#x7406;&#x5668;&#x4EE3;&#x7801;&#xFF0C;&#x4EE5;&#x4ECE;&#x7F16;&#x8BD1;&#x4E2D;&#x6392;&#x9664;&#x201C;&#x5C06;&#x8981;&#x5E9F;&#x5F03;&#x201D;&#x7684;&#x4EE3;&#x7801;&#x3002;</li>
</ul>
<p>GNU/Linux&#x4E0A;&#xFF0C;&#x4F7F;&#x7528;GNU&#x7F16;&#x8BD1;&#x5668;&#xFF0C;CMake&#x5C06;&#x751F;&#x6210;&#x4EE5;&#x4E0B;<code>messageExport.h</code>&#x5934;&#x6587;&#x4EF6;:</p>
<pre><code class="lang-cmake"><span class="hljs-comment">#ifndef message_EXPORT_H</span>
<span class="hljs-comment">#define message_EXPORT_H</span>
<span class="hljs-comment">#ifdef message_STATIC_DEFINE</span>
<span class="hljs-comment"># define message_EXPORT</span>
<span class="hljs-comment"># define message_NO_EXPORT</span>
<span class="hljs-comment">#else</span>
<span class="hljs-comment"># ifndef message_EXPORT</span>
<span class="hljs-comment"># ifdef message_shared_EXPORTS</span>
/* We are building this library */
<span class="hljs-comment"># define message_EXPORT __attribute__((visibility(&quot;default&quot;)))</span>
<span class="hljs-comment"># else</span>
/* We are using this library */
<span class="hljs-comment"># define message_EXPORT __attribute__((visibility(&quot;default&quot;)))</span>
<span class="hljs-comment"># endif</span>
<span class="hljs-comment"># endif</span>
<span class="hljs-comment"># ifndef message_NO_EXPORT</span>
<span class="hljs-comment"># define message_NO_EXPORT __attribute__((visibility(&quot;hidden&quot;)))</span>
<span class="hljs-comment"># endif</span>
<span class="hljs-comment">#endif</span>
<span class="hljs-comment">#ifndef message_DEPRECATED</span>
<span class="hljs-comment"># define message_DEPRECATED __attribute__ ((__deprecated__))</span>
<span class="hljs-comment">#endif</span>
<span class="hljs-comment">#ifndef message_DEPRECATED_EXPORT</span>
<span class="hljs-comment"># define message_DEPRECATED_EXPORT message_EXPORT message_DEPRECATED</span>
<span class="hljs-comment">#endif</span>
<span class="hljs-comment">#ifndef message_DEPRECATED_NO_EXPORT</span>
<span class="hljs-comment"># define message_DEPRECATED_NO_EXPORT message_NO_EXPORT message_DEPRECATED</span>
<span class="hljs-comment">#endif</span>
<span class="hljs-comment">#if 1 /* DEFINE_NO_DEPRECATED */</span>
<span class="hljs-comment"># ifndef message_NO_DEPRECATED</span>
<span class="hljs-comment"># define message_NO_DEPRECATED</span>
<span class="hljs-comment"># endif</span>
<span class="hljs-comment">#endif</span>
<span class="hljs-comment">#endif</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<code>message_EXPORT</code>&#x5B8F;&#xFF0C;&#x9884;&#x5148;&#x5904;&#x7406;&#x7528;&#x6237;&#x516C;&#x5F00;&#x7C7B;&#x548C;&#x51FD;&#x6570;&#x3002;&#x5F03;&#x7528;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5728;&#x524D;&#x9762;&#x52A0;&#x4E0A;<code>message_DEPRECATED</code>&#x5B8F;&#x6765;&#x5B9E;&#x73B0;&#x3002;</p>
<p>&#x4ECE;<code>messageExport.h</code>&#x5934;&#x6587;&#x4EF6;&#x7684;&#x5185;&#x5BB9;&#x53EF;&#x4EE5;&#x770B;&#x51FA;&#xFF0C;&#x6240;&#x6709;&#x7B26;&#x53F7;&#x90FD;&#x5E94;&#x8BE5;&#x5728;&#x9759;&#x6001;&#x5E93;&#x4E2D;&#x53EF;&#x89C1;&#xFF0C;&#x8FD9;&#x5C31;&#x662F;<code>message_STATIC_DEFINE</code>&#x5B8F;&#x8D77;&#x4E86;&#x4F5C;&#x7528;&#x3002;&#x5F53;&#x58F0;&#x660E;&#x4E86;&#x76EE;&#x6807;&#xFF0C;&#x6211;&#x4EEC;&#x5C31;&#x5C06;&#x5176;&#x8BBE;&#x7F6E;&#x4E3A;&#x7F16;&#x8BD1;&#x65F6;&#x5B9A;&#x4E49;&#x3002;&#x9759;&#x6001;&#x5E93;&#x7684;&#x5176;&#x4ED6;&#x76EE;&#x6807;&#x5C5E;&#x6027;&#x5982;&#x4E0B;:</p>
<ul>
<li><code>ARCHIVE_OUTPUT_NAME &quot;message&quot;</code>&#xFF1A;&#x8FD9;&#x5C06;&#x786E;&#x4FDD;&#x5E93;&#x6587;&#x4EF6;&#x7684;&#x540D;&#x79F0;&#x662F;<code>message</code>&#xFF0C;&#x800C;&#x4E0D;&#x662F;<code>message-static</code>&#x3002;</li>
<li><code>DEBUG_POSTFIX &quot;_sd&quot;</code>&#xFF1A;&#x8FD9;&#x5C06;&#x628A;&#x7ED9;&#x5B9A;&#x7684;&#x540E;&#x7F00;&#x9644;&#x52A0;&#x5230;&#x5E93;&#x540D;&#x79F0;&#x4E2D;&#x3002;&#x5F53;&#x76EE;&#x6807;&#x6784;&#x5EFA;&#x7C7B;&#x578B;&#x4E3A;Release&#x65F6;&#xFF0C;&#x4E3A;&#x9759;&#x6001;&#x5E93;&#x6DFB;&#x52A0;&quot;_sd&quot;&#x540E;&#x7F00;&#x3002;</li>
<li><code>RELEASE_POSTFIX &quot;_s&quot;</code>&#xFF1A;&#x8FD9;&#x4E0E;&#x524D;&#x9762;&#x7684;&#x5C5E;&#x6027;&#x7C7B;&#x4F3C;&#xFF0C;&#x5F53;&#x76EE;&#x6807;&#x6784;&#x5EFA;&#x7C7B;&#x578B;&#x4E3A;Release&#x65F6;&#xFF0C;&#x4E3A;&#x9759;&#x6001;&#x5E93;&#x6DFB;&#x52A0;&#x540E;&#x7F00;&#x201C;_s&#x201D;&#x3002;</li>
</ul>
<h2 id="&#x66F4;&#x591A;&#x4FE1;&#x606F;">&#x66F4;&#x591A;&#x4FE1;&#x606F;</h2>
<p>&#x6784;&#x5EFA;&#x52A8;&#x6001;&#x5E93;&#x65F6;&#xFF0C;&#x9690;&#x85CF;&#x5185;&#x90E8;&#x7B26;&#x53F7;&#x662F;&#x4E00;&#x4E2A;&#x5F88;&#x597D;&#x7684;&#x65B9;&#x5F0F;&#x3002;&#x8FD9;&#x610F;&#x5473;&#x7740;&#x5E93;&#x4F1A;&#x7F29;&#x5C0F;&#xFF0C;&#x56E0;&#x4E3A;&#x5411;&#x7528;&#x6237;&#x516C;&#x5F00;&#x7684;&#x5185;&#x5BB9;&#x8981;&#x5C0F;&#x4E8E;&#x5E93;&#x4E2D;&#x7684;&#x5185;&#x5BB9;&#x3002;&#x8FD9;&#x5B9A;&#x4E49;&#x4E86;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x4E8C;&#x8FDB;&#x5236;&#x63A5;&#x53E3;(ABI)&#xFF0C;&#x901A;&#x5E38;&#x60C5;&#x51B5;&#x4E0B;&#x5E94;&#x8BE5;&#x4E0E;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x7F16;&#x7A0B;&#x63A5;&#x53E3;(API)&#x4E00;&#x81F4;&#x3002;&#x8FD9;&#x5206;&#x4E24;&#x4E2A;&#x9636;&#x6BB5;&#x8FDB;&#x884C;&#xFF1A;</p>
<ol>
<li>&#x4F7F;&#x7528;&#x9002;&#x5F53;&#x7684;&#x7F16;&#x8BD1;&#x5668;&#x6807;&#x5FD7;&#x3002;</li>
<li>&#x4F7F;&#x7528;&#x9884;&#x5904;&#x7406;&#x5668;&#x53D8;&#x91CF;(&#x793A;&#x4F8B;&#x4E2D;&#x662F;<code>message_EXPORT</code>)&#x6807;&#x8BB0;&#x8981;&#x5BFC;&#x51FA;&#x7684;&#x7B26;&#x53F7;&#x3002;&#x7F16;&#x8BD1;&#x65F6;&#xFF0C;&#x5C06;&#x89E3;&#x9664;&#x8FD9;&#x4E9B;&#x7B26;&#x53F7;(&#x7C7B;&#x548C;&#x51FD;&#x6570;)&#x7684;&#x9690;&#x85CF;&#x3002;</li>
</ol>
<p>&#x9759;&#x6001;&#x5E93;&#x53EA;&#x662F;&#x76EE;&#x6807;&#x6587;&#x4EF6;&#x7684;&#x5F52;&#x6863;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x6E90;&#x4EE3;&#x7801;&#x7F16;&#x8BD1;&#x6210;&#x76EE;&#x6807;&#x6587;&#x4EF6;&#xFF0C;&#x7136;&#x540E;&#x5F52;&#x6863;&#x5668;&#x5C06;&#x5B83;&#x4EEC;&#x6346;&#x7ED1;&#x5230;&#x5F52;&#x6863;&#x6587;&#x4EF6;&#x4E2D;&#x3002;&#x8FD9;&#x65F6;&#x6CA1;&#x6709;ABI&#x7684;&#x6982;&#x5FF5;&#xFF1A;&#x6240;&#x6709;&#x7B26;&#x53F7;&#x5728;&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#x90FD;&#x662F;&#x53EF;&#x89C1;&#x7684;&#xFF0C;&#x7F16;&#x8BD1;&#x5668;&#x7684;&#x53EF;&#x89C1;&#x6807;&#x5FD7;&#x4E0D;&#x5F71;&#x54CD;&#x9759;&#x6001;&#x5F52;&#x6863;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x8981;&#x4ECE;&#x76F8;&#x540C;&#x7684;&#x6E90;&#x6587;&#x4EF6;&#x6784;&#x5EFA;&#x52A8;&#x6001;&#x548C;&#x9759;&#x6001;&#x5E93;&#xFF0C;&#x5219;&#x9700;&#x8981;&#x4E00;&#x79CD;&#x65B9;&#x6CD5;&#x6765;&#x8D4B;&#x4E88;<code>message_EXPORT</code>&#x9884;&#x5904;&#x7406;&#x53D8;&#x91CF;&#x610F;&#x4E49;&#xFF0C;&#x8FD9;&#x4E24;&#x79CD;&#x60C5;&#x51B5;&#x90FD;&#x4F1A;&#x51FA;&#x73B0;&#x5728;&#x4EE3;&#x7801;&#x4E2D;&#x3002;&#x8FD9;&#x91CC;&#x4F7F;&#x7528;<code>GenerateExportHeader.cmake</code>&#x6A21;&#x5757;&#xFF0C;&#x5B83;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x5305;&#x542B;&#x6240;&#x6709;&#x903B;&#x8F91;&#x7684;&#x5934;&#x6587;&#x4EF6;&#xFF0C;&#x7528;&#x4E8E;&#x7ED9;&#x51FA;&#x8FD9;&#x4E2A;&#x9884;&#x5904;&#x7406;&#x53D8;&#x91CF;&#x7684;&#x6B63;&#x786E;&#x5B9A;&#x4E49;&#x3002;&#x5BF9;&#x4E8E;&#x52A8;&#x6001;&#x5E93;&#xFF0C;&#x5B83;&#x5C06;&#x7ED9;&#x5B9A;&#x7684;&#x5E73;&#x53F0;&#x4E0E;&#x7F16;&#x8BD1;&#x5668;&#x76F8;&#x7EC4;&#x5408;&#x3002;&#x6CE8;&#x610F;&#xFF0C;&#x6839;&#x636E;&#x6784;&#x5EFA;&#x6216;&#x4F7F;&#x7528;&#x52A8;&#x6001;&#x5E93;&#xFF0C;&#x5B8F;&#x5B9A;&#x4E49;&#x4E5F;&#x4F1A;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x3002;&#x5E78;&#x8FD0;&#x7684;&#x662F;&#xFF0C;CMake&#x4E3A;&#x6211;&#x4EEC;&#x89E3;&#x51B3;&#x4E86;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x3002;&#x5BF9;&#x4E8E;&#x9759;&#x6001;&#x5E93;&#xFF0C;&#x5B83;&#x5C06;&#x6269;&#x5C55;&#x4E3A;&#x4E00;&#x4E2A;&#x7A7A;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x6267;&#x884C;&#x6211;&#x4EEC;&#x671F;&#x671B;&#x7684;&#x64CD;&#x4F5C;&#x2014;&#x2014;&#x4EC0;&#x4E48;&#x4E5F;&#x4E0D;&#x505A;&#x3002;</p>
<p>&#x7EC6;&#x5FC3;&#x7684;&#x8BFB;&#x8005;&#x4F1A;&#x6CE8;&#x610F;&#x5230;&#xFF0C;&#x6784;&#x5EFA;&#x6B64;&#x5904;&#x6240;&#x793A;&#x7684;&#x9759;&#x6001;&#x548C;&#x5171;&#x4EAB;&#x5E93;&#x5B9E;&#x9645;&#x4E0A;&#x9700;&#x8981;&#x7F16;&#x8BD1;&#x6E90;&#x4EE3;&#x7801;&#x4E24;&#x6B21;&#x3002;&#x5BF9;&#x4E8E;&#x6211;&#x4EEC;&#x7684;&#x7B80;&#x5355;&#x793A;&#x4F8B;&#x6765;&#x8BF4;&#xFF0C;&#x8FD9;&#x4E0D;&#x662F;&#x4E00;&#x4E2A;&#x5F88;&#x5927;&#x7684;&#x5F00;&#x9500;&#xFF0C;&#x4F46;&#x4F1A;&#x663E;&#x5F97;&#x76F8;&#x5F53;&#x9EBB;&#x70E6;&#xFF0C;&#x5373;&#x4F7F;&#x5BF9;&#x4E8E;&#x53EA;&#x6BD4;&#x793A;&#x4F8B;&#x7A0D;&#x5927;&#x4E00;&#x70B9;&#x7684;&#x9879;&#x76EE;&#x6765;&#x8BF4;&#xFF0C;&#x4E5F;&#x662F;&#x5982;&#x6B64;&#x3002;&#x4E3A;&#x4EC0;&#x4E48;&#x6211;&#x4EEC;&#x9009;&#x62E9;&#x8FD9;&#x79CD;&#x65B9;&#x6CD5;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x4F7F;&#x7528;&#x7B2C;1&#x7AE0;&#x7B2C;3&#x8282;&#x7684;&#x65B9;&#x5F0F;&#x5462;&#xFF1F;<code>OBJECT</code>&#x5E93;&#x8D1F;&#x8D23;&#x7F16;&#x8BD1;&#x5E93;&#x7684;&#x7B2C;&#x4E00;&#x6B65;&#xFF1A;&#x4ECE;&#x6E90;&#x6587;&#x4EF6;&#x5230;&#x5BF9;&#x8C61;&#x6587;&#x4EF6;&#x3002;&#x8BE5;&#x6B65;&#x9AA4;&#x4E2D;&#xFF0C;&#x9884;&#x5904;&#x7406;&#x5668;&#x5C06;&#x4ECB;&#x5165;&#x5E76;&#x8BA1;&#x7B97;<code>message_EXPORT</code>&#x3002;&#x7531;&#x4E8E;&#x5BF9;&#x8C61;&#x5E93;&#x7684;&#x7F16;&#x8BD1;&#x53EA;&#x53D1;&#x751F;&#x4E00;&#x6B21;&#xFF0C;<code>message_EXPORT</code>&#x88AB;&#x8BA1;&#x7B97;&#x4E3A;&#x6784;&#x5EFA;&#x52A8;&#x6001;&#x5E93;&#x5E93;&#x6216;&#x9759;&#x6001;&#x5E93;&#x517C;&#x5BB9;&#x7684;&#x503C;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x4E3A;&#x4E86;&#x907F;&#x514D;&#x6B67;&#x4E49;&#xFF0C;&#x6211;&#x4EEC;&#x9009;&#x62E9;&#x4E86;&#x66F4;&#x5065;&#x58EE;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x5373;&#x7F16;&#x8BD1;&#x4E24;&#x6B21;&#xFF0C;&#x4E3A;&#x7684;&#x5C31;&#x662F;&#x8BA9;&#x9884;&#x5904;&#x7406;&#x5668;&#x6B63;&#x786E;&#x5730;&#x8BC4;&#x4F30;&#x53D8;&#x91CF;&#x7684;&#x53EF;&#x89C1;&#x6027;&#x3002;</p>
<p><strong>NOTE</strong>:<em>&#x6709;&#x5173;&#x52A8;&#x6001;&#x5171;&#x4EAB;&#x5BF9;&#x8C61;&#x3001;&#x9759;&#x6001;&#x5B58;&#x6863;&#x548C;&#x7B26;&#x53F7;&#x53EF;&#x89C1;&#x6027;&#x7684;&#x66F4;&#x591A;&#x7EC6;&#x8282;&#xFF0C;&#x5EFA;&#x8BAE;&#x9605;&#x8BFB;:<a href="http://people.redhat.com/drepper/dsohowto.pdf" target="_blank">http://people.redhat.com/drepper/dsohowto.pdf</a></em></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="10.1-chinese.html" class="navigation navigation-prev " aria-label="Previous page: 10.1 安装项目">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="10.3-chinese.html" class="navigation navigation-next " aria-label="Next page: 10.3 输出目标">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"10.2 生成输出头文件","level":"1.13.2","depth":2,"next":{"title":"10.3 输出目标","level":"1.13.3","depth":2,"path":"content/chapter10/10.3-chinese.md","ref":"content/chapter10/10.3-chinese.md","articles":[]},"previous":{"title":"10.1 安装项目","level":"1.13.1","depth":2,"path":"content/chapter10/10.1-chinese.md","ref":"content/chapter10/10.1-chinese.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","search-pro","-sharing","github","pageview-count"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"github":{"url":"https://github.com/arcticfox1919"},"search-pro":{},"pageview-count":{},"highlight":{},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"陈晓伟 chenxiaowei","pdf":{"pageNumbers":false,"fontSize":30,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":30,"left":30,"top":30,"bottom":50}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"《CMake Cookbook》中文版","language":"zh-hans","gitbook":"*","description":"作为对《CMake Cookbook》英文版的中文翻译。","direction":"ltr"},"file":{"path":"content/chapter10/10.2-chinese.md","mtime":"2020-09-22T10:39:01.891Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-09-22T11:21:21.825Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

